import requests
import json
import jmespath

def login():
    data = {
        "method": "POST",
        "url": "https://api.admin.merchant.java.crmeb.net/api/admin/merchant/login",
        "params": {},
        "json":{
            "account": "18292417675", "pwd": "000000", "captchaVO": {},
        }
    }
    r = requests.request(**data)
    print(r.text)
   # pass

def create_goods():

    url = "http://124.70.39.201/adminapi/shop/goods"

    payload = json.dumps({
        "goods_type": "real",
        "goods_name": "tanghulu",
        "sub_title": "",
        "goods_image": "upload/attachment/image/202412/30/173554280390b9bba5e5755efb9a146a3c7d1129ad_local.jpg",
        "goods_video": "",
        "goods_category": [
            2,
            6
        ],
        "brand_id": 1,
        "poster_id": "",
        "label_ids": [],
        "service_ids": [],
        "supplier_id": "",
        "status": "1",
        "sort": "",
        "addon_shop_supplier": [],
        "spec_type": "single",
        "price": "10",
        "market_price": "",
        "cost_price": "",
        "stock": "100",
        "sku_no": "",
        "unit": "",
        "virtual_sale_num": "",
        "member_discount": "",
        "is_limit": 0,
        "limit_type": 1,
        "max_buy": "",
        "min_buy": "",
        "attr_format": "[]",
        "attr_id": "",
        "goods_desc": "<p>666</p>",
        "skuCheckAll": False,
        "skuIsIndeterminate": False,
        "skuCheckedCities": [],
        "delivery_type": [
            "express"
        ],
        "is_free_shipping": 1,
        "fee_type": "template",
        "delivery_money": "",
        "delivery_template_id": "",
        "goods_sku_data": {},
        "goods_spec_format": []
    })
    headers = {
        'lang': 'zh-cn',
        'token': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjEsInVzZXJuYW1lIjoiYWRtaW4iLCJpc3MiOiIxMjQuNzAuMzkuMjAxIiwiYXVkIjoiMTI0LjcwLjM5LjIwMSIsImlhdCI6MTczNTU0MDE4MCwibmJmIjoxNzM1NTQwMTgwLCJleHAiOjE3MzYxNDQ5ODAsImp0aSI6IjFfYWRtaW4ifQ.dotZL6MjkMB8VzQBw_8ZF7uXChE_rfof1i-XTDTWze4',
        'Content-Type': 'application/json'
    }

    response = requests.request("POST", url, headers=headers, data=payload)

    print(response.text)


def select_goods():
    url = "http://124.70.39.201/adminapi/shop/goods?page=1&limit=10&goods_name=tanghulu"

    payload = {}
    headers = {
        'lang': 'zh-cn',
        'token': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjEsInVzZXJuYW1lIjoiYWRtaW4iLCJpc3MiOiIxMjQuNzAuMzkuMjAxIiwiYXVkIjoiMTI0LjcwLjM5LjIwMSIsImlhdCI6MTczNTU0MDE4MCwibmJmIjoxNzM1NTQwMTgwLCJleHAiOjE3MzYxNDQ5ODAsImp0aSI6IjFfYWRtaW4ifQ.dotZL6MjkMB8VzQBw_8ZF7uXChE_rfof1i-XTDTWze4'
    }

    response = requests.request("GET", url, headers=headers, data=payload)

    print(response.text)

def up_goods():

    url = "http://124.70.39.201/adminapi/shop/goods/type"

    payload = {}
    headers = {
        'lang': 'zh-cn',
        'token': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjEsInVzZXJuYW1lIjoiYWRtaW4iLCJpc3MiOiIxMjQuNzAuMzkuMjAxIiwiYXVkIjoiMTI0LjcwLjM5LjIwMSIsImlhdCI6MTczNTU0MDE4MCwibmJmIjoxNzM1NTQwMTgwLCJleHAiOjE3MzYxNDQ5ODAsImp0aSI6IjFfYWRtaW4ifQ.dotZL6MjkMB8VzQBw_8ZF7uXChE_rfof1i-XTDTWze4'
    }

    response = requests.request("GET", url, headers=headers, data=payload)

    print(response.text)

def delete_goods():
    import requests
    import json

    url = "http://124.70.39.201/adminapi/shop/goods/status"

    payload = json.dumps({
        "goods_ids": 592,
        "status": 0
    })
    headers = {
        'lang': 'zh-cn',
        'token': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjEsInVzZXJuYW1lIjoiYWRtaW4iLCJpc3MiOiIxMjQuNzAuMzkuMjAxIiwiYXVkIjoiMTI0LjcwLjM5LjIwMSIsImlhdCI6MTczNTU0MDE4MCwibmJmIjoxNzM1NTQwMTgwLCJleHAiOjE3MzYxNDQ5ODAsImp0aSI6IjFfYWRtaW4ifQ.dotZL6MjkMB8VzQBw_8ZF7uXChE_rfof1i-XTDTWze4',
        'Content-Type': 'application/json'
    }

    response = requests.request("PUT", url, headers=headers, data=payload)

    print(response.text)

def goods_flow():
    login()
    create_goods()
    select_goods()
    up_goods()
    delete_goods()

if __name__ == '__main__':
    goods_flow()
